package com.everest.tribalapp;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Desa_Form7 extends Activity implements OnClickListener {

	private static String GMAIL_EMAIL_ID = "akatgelar@gmail.com";
	private static String GMAIL_ACCOUNT_PASSWORD = "akatsuki";
	private static String TO_ADDRESSES = "akatgelar@yahoo.co.id";
	private String value = "";
	private Button send;
	private Button prev;
	private EditText desa_f7_ans_username;
	private EditText desa_f7_ans_date;
	private EditText desa_f7_ans_responden;
	private EditText desa_f7_ans_phone;
	private EditText desa_f7_ans_long;
	private EditText desa_f7_ans_lan;

	private String desa_f1_1;
	private String desa_f1_2;
	private String desa_f1_3;
	private String desa_f1_4;
	private String desa_f1_5; 
	private String desa_f2_1;
	private String desa_f2_2;
	private String desa_f2_3;
	private String desa_f2_4;
	private String desa_f2_5;
	private String desa_f2_6a;
	private String desa_f2_6b;
	private String desa_f3_1a;
	private String desa_f3_1b;
	private String desa_f3_211;
	private String desa_f3_212;
	private String desa_f3_213;
	private String desa_f3_214;
	private String desa_f3_215;
	private String desa_f3_221;
	private String desa_f3_222;
	private String desa_f3_223;
	private String desa_f3_224;
	private String desa_f3_225;
	private String desa_f3_231;
	private String desa_f3_232;
	private String desa_f3_233;
	private String desa_f3_234;
	private String desa_f3_235;
	private String desa_f3_3;
	private String desa_f3_4;
	private String desa_f3_5a;
	private String desa_f3_5b;
	private String desa_f3_5c;
	private String desa_f3_5d;
	private String desa_f3_5e;
	private String desa_f4_1;
	private boolean desa_f4_2a;
	private boolean desa_f4_2b;
	private boolean desa_f4_2c;
	private boolean desa_f4_2d;
	private boolean desa_f4_2e;
	private boolean desa_f4_2f;
	private boolean desa_f4_2g;
	private String desa_f4_2h;
	private String desa_f4_3;
	private String desa_f4_4;
	private String desa_f4_5;
	private String desa_f4_6;
	private String desa_f4_7;
	private String desa_f4_8;
	private String desa_f4_9;
	private String desa_f4_10;
	private String desa_f4_11a;
	private String desa_f4_11ba;
	private String desa_f4_11bb;
	private String desa_f4_11bc;
	private String desa_f4_11bd;
	private String desa_f4_11c;
	private String desa_f4_12;
	private String desa_f4_13a;
	private String desa_f4_13b;
	private String desa_f4_13c;
	private String desa_f4_14a;
	private String desa_f4_14b;
	private String desa_f4_14c;
	private String desa_f4_14d;
	private String desa_f4_15;
	private String desa_f4_16a;
	private String desa_f4_16b;
	private String desa_f4_17;
	private String desa_f4_18;
	private String desa_f4_19;
	private String desa_f4_20;
	private String desa_f4_21a;
	private String desa_f4_21b;
	private boolean desa_f4_22a;
	private boolean desa_f4_22b;
	private boolean desa_f4_22c;
	private boolean desa_f4_22d;
	private String desa_f4_22e;
	private String desa_f5_1;
	private String desa_f5_2;
	private String desa_f5_3;
	private String desa_f5_4;
	private String desa_f5_6;
	private String desa_f5_8;
	private String desa_f5_10;
	private String desa_f5_11;
	private String desa_f5_12;
	private String desa_f5_13a;
	private String desa_f5_13b;
	private boolean desa_f5_5a;
	private boolean desa_f5_5b;
	private boolean desa_f5_5d;
	private boolean desa_f5_5c;
	private boolean desa_f5_7b;
	private boolean desa_f5_7a;
	private boolean desa_f5_9a;
	private boolean desa_f5_9b;
	private boolean desa_f5_9c;
	private boolean desa_f5_9d;
	private String desa_f6_1;
	private boolean desa_f6_2a;
	private boolean desa_f6_2b;
	private boolean desa_f6_3a;
	private boolean desa_f6_3b;
	private boolean desa_f6_3c;
	private boolean desa_f6_3d;
	private String desa_f7_1;
	private String desa_f7_2;
	private String desa_f7_3;
	private String desa_f7_4;
	private String desa_f7_5;
	private String desa_f7_6;
	public int i = 0;
	private Calendar c;
	private SimpleDateFormat df;
	private String formattedDate;
	private Button browse1;
	private Button browse2;
	private String filePath;
	static final int CUSTOM_DIALOG_ID = 1;
	private static final int PICK_IMAGE = 1;
	private final int CAMERA_RESULT = 0;
	private ImageView img;
	private String nameimage;
	private Bitmap bitmap;
	private String _path;
	private String newimgname;
	private Dialog dialog;
	private TextView fromgallery;
	private TextView takeimage;
	private String newloc;
	private String newimgloc;
	private String toname;
	private String filePath1;
	private String nameimage1;
	private int serverResponseCode;
	private String fileName;
	private String serverResponseMessage;
	protected int image_flag = 0;
	private ImageView img1;
	private int flag;
	private int serverResponseCode1;
	private String serverResponseMessage1;

	@Override
	public void onBackPressed() {
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Desa_Form7.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.desa_f7);
		Global.image_path1 = "";
		Global.image_path2 = "";
		desa_f7_ans_username = (EditText) findViewById(R.id.desa_f7_ans_username);
		desa_f7_ans_date = (EditText) findViewById(R.id.desa_f7_ans_date);
		desa_f7_ans_responden = (EditText) findViewById(R.id.desa_f7_ans_responden);
		desa_f7_ans_phone = (EditText) findViewById(R.id.desa_f7_ans_phone);
		desa_f7_ans_long = (EditText) findViewById(R.id.desa_f7_ans_long);
		desa_f7_ans_lan = (EditText) findViewById(R.id.desa_f7_ans_lan);
		browse1 = (Button) findViewById(R.id.browse1_desa);
		browse2 = (Button) findViewById(R.id.browse2_desa);
		img = (ImageView) findViewById(R.id.imageView1_desa);
		img1 = (ImageView) findViewById(R.id.imageView2_desa);
		browse1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					image_flag = 1;
					showDialog(CUSTOM_DIALOG_ID);

				} catch (Exception e) {
					System.out.println(e);
				}

			}
		});
		browse2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					image_flag = 2;
					showDialog(CUSTOM_DIALOG_ID);

				} catch (Exception e) {
					System.out.println(e);
				}

			}
		});
		desa_f7_ans_username.setText(Global.username.trim());
		desa_f7_ans_username.setFocusable(false);

		desa_f7_ans_date.setText(Global.date);
		desa_f7_ans_date.setFocusable(false);
		send = (Button) findViewById(R.id.desa_f7_send);
		prev = (Button) findViewById(R.id.desa_f7_prev);
		send.setOnClickListener(this);
		prev.setOnClickListener(this);
		boolean answer;
		answer = isOnline();
		if (answer) {
			LocationManager L = (LocationManager) getSystemService(LOCATION_SERVICE);
			if (L.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
				LocationListener ll = new mylocationlistener();
				L.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,
						0, ll);
			} else {
				Intent in = new Intent(
						android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
				startActivity(in);
			}
		} else {
			Toast.makeText(getApplicationContext(), "Enable Your Internet",
					3000).show();
		}
	}

	public void toast_msg() {
		LayoutInflater inflater = getLayoutInflater();

		View layout = inflater.inflate(R.layout.custom_toast,
				(ViewGroup) findViewById(R.id.custom_toast_layout_id));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(value);
		Toast toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(layout);
		toast.show();
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == send.getId()) {
			desa_f7_1 = Global.username.toString().trim();
			desa_f7_2 = desa_f7_ans_date.getText().toString().trim();
			desa_f7_3 = desa_f7_ans_phone.getText().toString().trim();
			desa_f7_4 = desa_f7_ans_responden.getText().toString().trim();
			desa_f7_5 = desa_f7_ans_lan.getText().toString().trim();
			desa_f7_6 = desa_f7_ans_long.getText().toString().trim();

			// user1=URLEncoder.encode(user1,"UTF-8");
			SharedPreferences preferences1 = getSharedPreferences(
					"desa_f1_details", MODE_PRIVATE);
			desa_f1_1 = preferences1.getString("1_1", " ");
			desa_f1_2 = preferences1.getString("1_2", " ");
			desa_f1_3 = preferences1.getString("1_3", " ");
			desa_f1_4 = preferences1.getString("1_4", " ");
			desa_f1_5 = preferences1.getString("1_5", " "); 
			try {
				desa_f1_5 = URLEncoder.encode(desa_f1_5, "UTF-8"); 
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			SharedPreferences preferences2 = getSharedPreferences(
					"desa_f2_details", MODE_PRIVATE);
			desa_f2_1 = preferences2.getString("2_1", " ");
			desa_f2_2 = preferences2.getString("2_2", " ");
			desa_f2_3 = preferences2.getString("2_3", " ");
			desa_f2_4 = preferences2.getString("2_4", " ");
			desa_f2_5 = preferences2.getString("2_5", " ");
			desa_f2_6a = preferences2.getString("2_6a", " ");
			desa_f2_6b = preferences2.getString("2_6b", " ");
			try {
				desa_f2_1 = URLEncoder.encode(desa_f2_1, "UTF-8");
				desa_f2_2 = URLEncoder.encode(desa_f2_2, "UTF-8");
				desa_f2_3 = URLEncoder.encode(desa_f2_3, "UTF-8");
				desa_f2_4 = URLEncoder.encode(desa_f2_4, "UTF-8");
				desa_f2_5 = URLEncoder.encode(desa_f2_5, "UTF-8");
				desa_f2_6a = URLEncoder.encode(desa_f2_6a, "UTF-8");
				desa_f2_6b = URLEncoder.encode(desa_f2_6b, "UTF-8");
			} catch (Exception exception) {
				exception.printStackTrace();
			}
			SharedPreferences preferences3 = getSharedPreferences(
					"desa_f3_details", MODE_PRIVATE);
			desa_f3_1a = preferences3.getString("3_1a", " ");
			desa_f3_1b = preferences3.getString("3_1b", " ");
			desa_f3_211 = preferences3.getString("3_211", " ");
			desa_f3_212 = preferences3.getString("3_212", " ");
			desa_f3_213 = preferences3.getString("3_213", " ");
			desa_f3_214 = preferences3.getString("3_214", " ");
			desa_f3_215 = preferences3.getString("3_215", " ");
			desa_f3_221 = preferences3.getString("3_221", " ");
			desa_f3_222 = preferences3.getString("3_222", " ");
			desa_f3_223 = preferences3.getString("3_223", " ");
			desa_f3_224 = preferences3.getString("3_224", " ");
			desa_f3_225 = preferences3.getString("3_225", " ");
			desa_f3_231 = preferences3.getString("3_231", " ");
			desa_f3_232 = preferences3.getString("3_232", " ");
			desa_f3_233 = preferences3.getString("3_233", " ");
			desa_f3_234 = preferences3.getString("3_234", " ");
			desa_f3_235 = preferences3.getString("3_235", " ");
			desa_f3_3 = preferences3.getString("3_3", " ");
			desa_f3_4 = preferences3.getString("3_4", " ");
			desa_f3_5a = preferences3.getString("3_5a", " ");
			desa_f3_5b = preferences3.getString("3_5b", " ");
			desa_f3_5c = preferences3.getString("3_5c", " ");
			desa_f3_5d = preferences3.getString("3_5d", " ");
			desa_f3_5e = preferences3.getString("3_5e", " ");
			try {
				desa_f3_1a = URLEncoder.encode(desa_f3_1a, "UTF-8");
				desa_f3_1b = URLEncoder.encode(desa_f3_1b, "UTF-8");
				desa_f3_211 = URLEncoder.encode(desa_f3_211, "UTF-8");
				desa_f3_212 = URLEncoder.encode(desa_f3_212, "UTF-8");
				desa_f3_213 = URLEncoder.encode(desa_f3_213, "UTF-8");
				desa_f3_214 = URLEncoder.encode(desa_f3_214, "UTF-8");
				desa_f3_215 = URLEncoder.encode(desa_f3_215, "UTF-8");
				desa_f3_221 = URLEncoder.encode(desa_f3_221, "UTF-8");
				desa_f3_222 = URLEncoder.encode(desa_f3_222, "UTF-8");
				desa_f3_223 = URLEncoder.encode(desa_f3_223, "UTF-8");
				desa_f3_224 = URLEncoder.encode(desa_f3_224, "UTF-8");
				desa_f3_225 = URLEncoder.encode(desa_f3_225, "UTF-8");
				desa_f3_231 = URLEncoder.encode(desa_f3_231, "UTF-8");
				desa_f3_232 = URLEncoder.encode(desa_f3_232, "UTF-8");
				desa_f3_233 = URLEncoder.encode(desa_f3_233, "UTF-8");
				desa_f3_234 = URLEncoder.encode(desa_f3_234, "UTF-8");
				desa_f3_235 = URLEncoder.encode(desa_f3_235, "UTF-8");
				desa_f3_3 = URLEncoder.encode(desa_f3_3, "UTF-8");
				desa_f3_4 = URLEncoder.encode(desa_f3_4, "UTF-8");
				desa_f3_5a = URLEncoder.encode(desa_f3_5a, "UTF-8");
				desa_f3_5b = URLEncoder.encode(desa_f3_5b, "UTF-8");
				desa_f3_5c = URLEncoder.encode(desa_f3_5c, "UTF-8");
				desa_f3_5d = URLEncoder.encode(desa_f3_5d, "UTF-8");
				desa_f3_5e = URLEncoder.encode(desa_f3_5e, "UTF-8");
			} catch (Exception e) {
				e.printStackTrace();
			}
			SharedPreferences preferences4 = getSharedPreferences(
					"desa_f4_details", MODE_PRIVATE);
			desa_f4_1 = preferences4.getString("4_1", " ");
			desa_f4_2a = preferences4.getBoolean("4_2a", false);
			desa_f4_2b = preferences4.getBoolean("4_2b", false);
			desa_f4_2c = preferences4.getBoolean("4_2c", false);
			desa_f4_2d = preferences4.getBoolean("4_2d", false);
			desa_f4_2e = preferences4.getBoolean("4_2e", false);
			desa_f4_2f = preferences4.getBoolean("4_2f", false);
			desa_f4_2g = preferences4.getBoolean("4_2g", false);
			desa_f4_2h = preferences4.getString("4_2h", " ");
			desa_f4_3 = preferences4.getString("4_3", " ");
			desa_f4_4 = preferences4.getString("4_4", " ");
			desa_f4_5 = preferences4.getString("4_5", " ");
			desa_f4_6 = preferences4.getString("4_6", " ");
			desa_f4_7 = preferences4.getString("4_7", " ");
			desa_f4_8 = preferences4.getString("4_8", " ");
			desa_f4_9 = preferences4.getString("4_9", " "); 
			desa_f4_10 = preferences4.getString("4_10", " ");
			desa_f4_11a = preferences4.getString("4_11a", " ");
			desa_f4_11ba = preferences4.getString("4_11ba", " ");
			desa_f4_11bb = preferences4.getString("4_11bb", " ");
			desa_f4_11bc = preferences4.getString("4_11bc", " ");
			desa_f4_11bd = preferences4.getString("4_11bd", " ");
			desa_f4_11c = preferences4.getString("4_11c", " ");
			desa_f4_12 = preferences4.getString("4_12", " "); 
			desa_f4_13a = preferences4.getString("4_13a", " ");
			desa_f4_13b = preferences4.getString("4_13b", " ");
			desa_f4_13c = preferences4.getString("4_13c", " ");
			desa_f4_14a = preferences4.getString("4_14a", " ");
			desa_f4_14b = preferences4.getString("4_14b", " ");
			desa_f4_14c = preferences4.getString("4_14c", " ");
			desa_f4_14d = preferences4.getString("4_14d", " ");
			desa_f4_15 = preferences4.getString("4_15", " ");
			desa_f4_16a = preferences4.getString("4_16a", " ");
			desa_f4_16b = preferences4.getString("4_16b", " ");
			desa_f4_17 = preferences4.getString("4_17", " ");
			desa_f4_18 = preferences4.getString("4_18", " ");
			desa_f4_19 = preferences4.getString("4_19", " ");
			desa_f4_20 = preferences4.getString("4_20", " ");
			desa_f4_21a = preferences4.getString("4_21a", " ");
			desa_f4_21b = preferences4.getString("4_21b", " ");
			desa_f4_22a = preferences4.getBoolean("4_22a", false); 
			desa_f4_22b = preferences4.getBoolean("4_22b", false); 
			desa_f4_22c = preferences4.getBoolean("4_22c", false); 
			desa_f4_22d = preferences4.getBoolean("4_22d", false); 
			desa_f4_22e = preferences4.getString("4_21e", " ");
			try {
				desa_f4_1 = URLEncoder.encode(desa_f4_1, "UTF-8"); 
				desa_f4_3 = URLEncoder.encode(desa_f4_3, "UTF-8");
				desa_f4_4 = URLEncoder.encode(desa_f4_4, "UTF-8");
				desa_f4_5 = URLEncoder.encode(desa_f4_5, "UTF-8");
				desa_f4_6 = URLEncoder.encode(desa_f4_6, "UTF-8");
				desa_f4_7 = URLEncoder.encode(desa_f4_7, "UTF-8");
				desa_f4_8 = URLEncoder.encode(desa_f4_8, "UTF-8"); 
				desa_f4_9 = URLEncoder.encode(desa_f4_9, "UTF-8"); 
				desa_f4_10 = URLEncoder.encode(desa_f4_10, "UTF-8");
				desa_f4_11a = URLEncoder.encode(desa_f4_11a, "UTF-8");
				desa_f4_11ba = URLEncoder.encode(desa_f4_11ba, "UTF-8");
				desa_f4_11bb = URLEncoder.encode(desa_f4_11bb, "UTF-8");
				desa_f4_11bc = URLEncoder.encode(desa_f4_11bc, "UTF-8");
				desa_f4_11bd = URLEncoder.encode(desa_f4_11bd, "UTF-8");
				desa_f4_11c = URLEncoder.encode(desa_f4_11c, "UTF-8");
				desa_f4_12 = URLEncoder.encode(desa_f4_12, "UTF-8"); 
				desa_f4_13a = URLEncoder.encode(desa_f4_13a, "UTF-8");
				desa_f4_13b = URLEncoder.encode(desa_f4_13b, "UTF-8");
				desa_f4_13c = URLEncoder.encode(desa_f4_13c, "UTF-8"); 
				desa_f4_14a = URLEncoder.encode(desa_f4_14a, "UTF-8");
				desa_f4_14b = URLEncoder.encode(desa_f4_14b, "UTF-8");
				desa_f4_14c = URLEncoder.encode(desa_f4_14c, "UTF-8");
				desa_f4_14d = URLEncoder.encode(desa_f4_14d, "UTF-8");
				desa_f4_15 = URLEncoder.encode(desa_f4_15, "UTF-8");
				desa_f4_16a = URLEncoder.encode(desa_f4_16a, "UTF-8");
				desa_f4_16b = URLEncoder.encode(desa_f4_16b, "UTF-8");
				desa_f4_17 = URLEncoder.encode(desa_f4_17, "UTF-8");
				desa_f4_18 = URLEncoder.encode(desa_f4_18, "UTF-8");
				desa_f4_19 = URLEncoder.encode(desa_f4_19, "UTF-8");
				desa_f4_20 = URLEncoder.encode(desa_f4_20, "UTF-8");
				desa_f4_21a = URLEncoder.encode(desa_f4_21a, "UTF-8");
				desa_f4_21b = URLEncoder.encode(desa_f4_21b, "UTF-8");
				desa_f4_22e = URLEncoder.encode(desa_f4_22e, "UTF-8");

			} catch (Exception exception) {
				exception.printStackTrace();
			}
			SharedPreferences preferences5 = getSharedPreferences(
					"desa_f5_details", MODE_PRIVATE);
			desa_f5_1 = preferences5.getString("5_1", " ");
			desa_f5_2 = preferences5.getString("5_2", " ");
			desa_f5_3 = preferences5.getString("5_3", " ");
			desa_f5_4 = preferences5.getString("5_4", " ");
			desa_f5_5a = preferences5.getBoolean("5_5a", false);
			desa_f5_5b = preferences5.getBoolean("5_5b", false);
			desa_f5_5c = preferences5.getBoolean("5_5c", false);
			desa_f5_5d = preferences5.getBoolean("5_5d", false);
			desa_f5_6 = preferences5.getString("5_6", " ");
			desa_f5_7a = preferences5.getBoolean("5_7a", false);
			desa_f5_7b = preferences5.getBoolean("5_7b", false);
			desa_f5_8 = preferences5.getString("5_8", " ");
			desa_f5_9a = preferences5.getBoolean("5_9a", false);
			desa_f5_9b = preferences5.getBoolean("5_9b", false);
			desa_f5_9c = preferences5.getBoolean("5_9c", false);
			desa_f5_9d = preferences5.getBoolean("5_9d", false);
			desa_f5_10 = preferences5.getString("5_10", " ");
			desa_f5_11 = preferences5.getString("5_11", " ");
			desa_f5_12 = preferences5.getString("5_12", " ");
			desa_f5_13a = preferences5.getString("5_13a", " ");
			desa_f5_13b = preferences5.getString("5_13b", " ");
			try {
				desa_f5_1 = URLEncoder.encode(desa_f5_1, "UTF-8");
				desa_f5_2 = URLEncoder.encode(desa_f5_2, "UTF-8");
				desa_f5_3 = URLEncoder.encode(desa_f5_3, "UTF-8");
				desa_f5_4 = URLEncoder.encode(desa_f5_4, "UTF-8");
				desa_f5_6 = URLEncoder.encode(desa_f5_6, "UTF-8");
				desa_f5_8 = URLEncoder.encode(desa_f5_8, "UTF-8");
				desa_f5_10 = URLEncoder.encode(desa_f5_10, "UTF-8");
				desa_f5_11 = URLEncoder.encode(desa_f5_11, "UTF-8");
				desa_f5_12 = URLEncoder.encode(desa_f5_12, "UTF-8");
				desa_f5_13a = URLEncoder.encode(desa_f5_13a, "UTF-8");
				desa_f5_13b = URLEncoder.encode(desa_f5_13b, "UTF-8");
			} catch (Exception exception) {
				exception.printStackTrace();
			}
			SharedPreferences preferences6 = getSharedPreferences(
					"desa_f6_details", MODE_PRIVATE);
			desa_f6_1 = preferences6.getString("6_1", " ");
			desa_f6_2a = preferences6.getBoolean("6_2a", false);
			desa_f6_2b = preferences6.getBoolean("6_2b", false);
			desa_f6_3a = preferences6.getBoolean("6_3a", false);
			desa_f6_3b = preferences6.getBoolean("6_3b", false);
			desa_f6_3c = preferences6.getBoolean("6_3c", false);
			desa_f6_3d = preferences6.getBoolean("6_3d", false);
			try {
				desa_f6_1 = URLEncoder.encode(desa_f6_1, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}

			boolean answer;
			answer = isOnline();
			System.out.println(answer);

			if (answer) {
				new upload().execute();

			} else {
				/*
				SQLiteAdapter_DesaPinter desaPinter = new SQLiteAdapter_DesaPinter(
						getApplicationContext());
				desaPinter.openToWrite();
				desaPinter.insert(desa_f1_1, desa_f1_2, desa_f1_3, desa_f1_4,
						desa_f1_5,   desa_f2_1, desa_f2_2, desa_f2_3,
						desa_f2_4, desa_f2_5, desa_f2_6a, desa_f2_6b,
						desa_f3_1a, desa_f3_1b, desa_f3_211, desa_f3_212,
						desa_f3_213, desa_f3_214, desa_f3_215, desa_f3_221,
						desa_f3_222, desa_f3_223, desa_f3_224, desa_f3_225,
						desa_f3_231, desa_f3_232, desa_f3_233, desa_f3_234,
						desa_f3_235, desa_f3_3, desa_f3_4, desa_f3_5a,
						desa_f3_5b, desa_f3_5c, desa_f3_5d,  desa_f4_1,
						desa_f4_2, desa_f4_3, desa_f4_4, desa_f4_5, desa_f4_6,
						desa_f4_7, desa_f4_8, desa_f4_9a, desa_f4_9b,
						desa_f4_9c, desa_f4_10, desa_f4_11a, desa_f4_11b,
						desa_f4_12a, desa_f4_12b, desa_f4_13, desa_f4_14a,
						desa_f4_14b, desa_f4_15, desa_f4_16, desa_f4_17,
						desa_f4_18, desa_f4_19a, desa_f4_19b, "" + desa_f4_20a,
						"" + desa_f4_20b, "" + desa_f4_20c, "" + desa_f4_20d,
						desa_f5_1, desa_f5_2, desa_f5_3, desa_f5_4, ""
								+ desa_f5_5a, "" + desa_f5_5b, "" + desa_f5_5c,
						"" + desa_f5_5d, desa_f5_6, "" + desa_f5_7a, ""
								+ desa_f5_7b, desa_f5_8, "" + desa_f5_9a, ""
								+ desa_f5_9b, "" + desa_f5_9c, "" + desa_f5_9d,
						desa_f5_10, desa_f5_11, desa_f5_12, desa_f5_13a,
						desa_f5_13b, desa_f6_1, "" + desa_f6_2, "" + desa_f6_3,
						desa_f7_1, desa_f7_2, desa_f7_3, desa_f7_4, desa_f7_5,
						desa_f7_6, "img", "img", Global.desa_year);
				desaPinter.close();
				String detail = "desa_f1_1=" + desa_f1_1 + "&desa_f1_2="
						+ desa_f1_2 + "&f1_3=" + desa_f1_3 + "&f1_4="
						+ desa_f1_4 + "&f1_5=" + desa_f1_5 + "&f2_1=" + desa_f2_1 + "&f2_2="
						+ desa_f2_2 + "&f2_3=" + desa_f2_3 + "&f2_4="
						+ desa_f2_4 + "&f2_5=" + desa_f2_5 + "&f2_6a="
						+ desa_f2_6a + "&f2_6b=" + desa_f2_6b + "&f3_1a="
						+ desa_f3_1a + "&f3_1b=" + desa_f3_1b + "&f3_211="
						+ desa_f3_211 + "&f3_212=" + desa_f3_212 + "&f3_213="
						+ desa_f3_213 + "&f3_214=" + desa_f3_214 + "&f3_215="
						+ desa_f3_215 + "&f3_221=" + desa_f3_221 + "&f3_222="
						+ desa_f3_222 + "&f3_223=" + desa_f3_223 + "&f3_224="
						+ desa_f3_224 + "&f3_225=" + desa_f3_225 + "&f3_231="
						+ desa_f3_231 + "&f3_232=" + desa_f3_232 + "&f3_233="
						+ desa_f3_233 + "&f3_234=" + desa_f3_234 + "&f3_235="
						+ desa_f3_235 + "&f3_3=" + desa_f3_3 + "&f3_4="
						+ desa_f3_4 + "&f3_5a=" + desa_f3_5a + "&f3_5b="
						+ desa_f3_5b + "&f3_5c=" + desa_f3_5c + "&f3_5d="
						+ desa_f3_5d + "&f3_5e=" + desa_f3_5e + "&f4_1=" + desa_f4_1 + "&f4_2="
						+ desa_f4_2 + "&f4_3=" + desa_f4_3 + "&f4_4="
						+ desa_f4_4 + "&f4_5=" + desa_f4_5 + "&f4_6="
						+ desa_f4_6 + "&f4_7=" + desa_f4_7 + "&f4_8="
						+ desa_f4_8 + "&f4_9a=" + desa_f4_9a + "&f4_9b="
						+ desa_f4_9b + "&f4_9c=" + desa_f4_9c + "&f4_10="
						+ desa_f4_10 + "&f4_11a=" + desa_f4_11a + "&f4_11b="
						+ desa_f4_11b + "&f4_12a=" + desa_f4_12a + "&f4_12b="
						+ desa_f4_12b + "&f4_13=" + desa_f4_13 + "&f4_14a="
						+ desa_f4_14a + "&f4_14b=" + desa_f4_14b + "&f4_15="
						+ desa_f4_15 + "&f4_16=" + desa_f4_16 + "&f4_17="
						+ desa_f4_17 + "&f4_18=" + desa_f4_18 + "&f4_19a="
						+ desa_f4_19a + "&f4_19b=" + desa_f4_19b + "&f4_20a="
						+ desa_f4_20a + "&f4_20b=" + desa_f4_20a + "&f4_20c="
						+ desa_f4_20a + "&f4_20d=" + desa_f4_20a + "&f5_1="
						+ desa_f5_1 + "&f5_2=" + desa_f5_2 + "&f5_3="
						+ desa_f5_3 + "&f5_4=" + desa_f5_4 + "&f5_5a="
						+ desa_f5_5a + "&f5_5b=" + desa_f5_5b + "&f5_5c="
						+ desa_f5_5c + "&f5_5d=" + desa_f5_5d + "&f5_6="
						+ desa_f5_6 + "&f5_7a=" + desa_f5_7a + "&f5_7b="
						+ desa_f5_7b + "&f5_8=" + desa_f5_8 + "&f5_9a="
						+ desa_f5_9a + "&f5_9b=" + desa_f5_9b + "&f5_9c="
						+ desa_f5_9c + "&f5_9d=" + desa_f5_9d + "&f5_10="
						+ desa_f5_10 + "&f5_11=" + desa_f5_11 + "&f5_12="
						+ desa_f5_12 + "&f5_13a=" + desa_f5_13a + "&f5_13b="
						+ desa_f5_13b + "&f6_1=" + desa_f6_1 + "&f6_2="
						+ desa_f6_2 + "&f6_3=" + desa_f6_3 + "&f7_1="
						+ desa_f7_1 + "&f7_2=" + desa_f7_2 + "&f7_3="
						+ desa_f7_3 + "&f7_5=" + desa_f7_5 + "&f7_6="
						+ desa_f7_6 + "&f7_4=" + desa_f7_4;
				Intent intent = new Intent(getApplicationContext(),
						SmsSendFunction1.class);
				intent.putExtra("detail", detail);
				startActivity(intent);
				Desa_Form7.this.finish();
			*/
			}

		} else if (v.getId() == prev.getId()) {
			System.out.println(Global.image_path1 + "   " + Global.image_path2);
			Intent intent = new Intent(getApplicationContext(),
					Desa_Form6.class);
			startActivity(intent);
			Desa_Form7.this.finish();
		}
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		SharedPreferences preferences = getSharedPreferences("desa_f7_details",
				MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString("7_username", Global.username.toString().trim());
		editor.putString("7_date", desa_f7_ans_date.getText().toString().trim());
		editor.putString("7_lat", desa_f7_ans_lan.getText().toString().trim());
		editor.putString("7_lng", desa_f7_ans_long.getText().toString().trim());
		editor.putString("7_phone", desa_f7_ans_phone.getText().toString()
				.trim());
		editor.putString("7_responden", desa_f7_ans_responden.getText()
				.toString().trim());
		editor.commit();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		SharedPreferences preferences = getSharedPreferences("desa_f7_details",
				MODE_PRIVATE);
		desa_f7_ans_username.setText(Global.username);
		desa_f7_ans_date.setText(Global.date);
		desa_f7_ans_lan.setText(preferences.getString("7_lat", ""));
		desa_f7_ans_long.setText(preferences.getString("7_lng", ""));
		desa_f7_ans_phone.setText(preferences.getString("7_phone", ""));
		desa_f7_ans_responden.setText(preferences.getString("7_responden", ""));
	}

	class upload extends AsyncTask {

		ProgressDialog pd = null;

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			super.onPreExecute();
			serverResponseCode = 200;
			serverResponseCode1 = 200;
			if (!Global.image_path1.isEmpty()) {
				// serverResponseCode=0;
				int i = doing();
			}
			if (!Global.image_path2.isEmpty()) {
				// serverResponseCode1=0;
				int i1 = doing1();
				// new Check().execute();
			}
			  

		}

		@Override
		protected Object doInBackground(Object... arg0) {
			if (!Global.image_path1.isEmpty()) {
				// serverResponseCode=0;
				int i = doing();
			}
			if (!Global.image_path2.isEmpty()) {
				// serverResponseCode1=0;
				int i1 = doing1();
				// new Check().execute();
			}
			return null;
		}

		@Override
		protected void onPostExecute(Object result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			if (serverResponseCode == 200 && serverResponseCode1 == 200) {
				new Check().execute();
			}
		}

	}

	class Check extends AsyncTask {

		private String json;
		private JSONObject jsonobject;
		private String code;
		private String msg;
		public String url;

		@Override
		protected void onPreExecute() {
			super.onPreExecute(); 
				url = Global.desa_2013_url
						+"&sd_1_1="+desa_f1_1
						+"&sd_1_2="+desa_f1_2
						+"&sd_1_3="+desa_f1_3
						+"&sd_1_4="+desa_f1_4
						+"&sd_1_5="+desa_f1_5
						+"&sd_2_1="+desa_f2_1
						+"&sd_2_2="+desa_f2_2
						+"&sd_2_3="+desa_f2_3
						+"&sd_2_4="+desa_f2_4
						+"&sd_2_5="+desa_f2_5
						+"&sd_2_6a="+desa_f2_6a
						+"&sd_2_6b="+desa_f2_6b
						+"&sd_3_1a="+desa_f3_1a
						+"&sd_3_1b="+desa_f3_1b
						+"&sd_3_211="+desa_f3_211
						+"&sd_3_212="+desa_f3_212
						+"&sd_3_213="+desa_f3_213
						+"&sd_3_214="+desa_f3_214
						+"&sd_3_215="+desa_f3_215
						+"&sd_3_221="+desa_f3_221
						+"&sd_3_222="+desa_f3_222
						+"&sd_3_223="+desa_f3_223
						+"&sd_3_224="+desa_f3_224
						+"&sd_3_225="+desa_f3_225
						+"&sd_3_231="+desa_f3_231
						+"&sd_3_232="+desa_f3_232
						+"&sd_3_233="+desa_f3_233
						+"&sd_3_234="+desa_f3_234
						+"&sd_3_235="+desa_f3_235
						+"&sd_3_3="+desa_f3_3
						+"&sd_3_4="+desa_f3_4
						+"&sd_3_5a="+desa_f3_5a
						+"&sd_3_5b="+desa_f3_5b
						+"&sd_3_5c="+desa_f3_5c
						+"&sd_3_5d="+desa_f3_5d
						+"&sd_3_5e="+desa_f3_5e
						+"&sd_4_1="+desa_f4_1
						+"&sd_4_2a="+desa_f4_2a
						+"&sd_4_2b="+desa_f4_2b
						+"&sd_4_2c="+desa_f4_2c
						+"&sd_4_2d="+desa_f4_2d
						+"&sd_4_2e="+desa_f4_2e
						+"&sd_4_2f="+desa_f4_2f
						+"&sd_4_2g="+desa_f4_2g
						+"&sd_4_2h="+desa_f4_2h
						+"&sd_4_3="+desa_f4_3
						+"&sd_4_4="+desa_f4_4
						+"&sd_4_5="+desa_f4_5
						+"&sd_4_6="+desa_f4_6
						+"&sd_4_7="+desa_f4_7
						+"&sd_4_8="+desa_f4_8
						+"&sd_4_9="+desa_f4_9
						+"&sd_4_10="+desa_f4_10
						+"&sd_4_11a="+desa_f4_11a
						+"&sd_4_11ba="+desa_f4_11ba
						+"&sd_4_11bb="+desa_f4_11bb
						+"&sd_4_11bc="+desa_f4_11bc
						+"&sd_4_11bd="+desa_f4_11bd
						+"&sd_4_11c="+desa_f4_11c
						+"&sd_4_12="+desa_f4_12
						+"&sd_4_13a="+desa_f4_13a
						+"&sd_4_13b="+desa_f4_13b
						+"&sd_4_13c="+desa_f4_13c
						+"&sd_4_14a="+desa_f4_14a
						+"&sd_4_14b="+desa_f4_14b
						+"&sd_4_14c="+desa_f4_14c
						+"&sd_4_14d="+desa_f4_14d
						+"&sd_4_15="+desa_f4_15
						+"&sd_4_16a="+desa_f4_16a
						+"&sd_4_16b="+desa_f4_16b
						+"&sd_4_17="+desa_f4_17
						+"&sd_4_18="+desa_f4_18
						+"&sd_4_19="+desa_f4_19
						+"&sd_4_20="+desa_f4_20
						+"&sd_4_21a="+desa_f4_21a
						+"&sd_4_21b="+desa_f4_21b
						+"&sd_4_22a="+desa_f4_22a
						+"&sd_4_22b="+desa_f4_22b
						+"&sd_4_22c="+desa_f4_22c
						+"&sd_4_22d="+desa_f4_22d
						+"&sd_4_22e="+desa_f4_22e
						+"&sd_5_1="+desa_f5_1
						+"&sd_5_2="+desa_f5_2
						+"&sd_5_3="+desa_f5_3
						+"&sd_5_4="+desa_f5_4
						+"&sd_5_5a="+desa_f5_5a
						+"&sd_5_5b="+desa_f5_5b
						+"&sd_5_5c="+desa_f5_5c
						+"&sd_5_5d="+desa_f5_5d
						+"&sd_5_6="+desa_f5_6
						+"&sd_5_7a="+desa_f5_7a
						+"&sd_5_7b="+desa_f5_7b
						+"&sd_5_8="+desa_f5_8
						+"&sd_5_9a="+desa_f5_9a
						+"&sd_5_9b="+desa_f5_9b
						+"&sd_5_9c="+desa_f5_9c
						+"&sd_5_9d="+desa_f5_9d
						+"&sd_5_10="+desa_f5_10
						+"&sd_5_11="+desa_f5_11
						+"&sd_5_12="+desa_f5_12
						+"&sd_5_13a="+desa_f5_13a
						+"&sd_5_13b="+desa_f5_13b
						+"&sd_6_1="+desa_f6_1
						+"&sd_6_2a="+desa_f6_2a
						+"&sd_6_2b="+desa_f6_2b
						+"&sd_6_3a="+desa_f6_3a
						+"&sd_6_3b="+desa_f6_3b
						+"&sd_6_3c="+desa_f6_3c
						+"&sd_6_3d="+desa_f6_3d
						+"&sd_7_1="+desa_f7_1
						+"&sd_7_2="+desa_f7_2
						+"&sd_7_3="+desa_f7_3
						+"&sd_7_4="+desa_f7_4
						+"&sd_7_5="+desa_f7_5
						+"&sd_7_6="+desa_f7_6;

				url = url.replace("+", "%2B");
				url = url.replace(" ", "%20");
				System.out.println(url);
			
		}

		@Override
		protected Object doInBackground(Object... params) {

			try {
				json = JSONfunctions.getStringContent(url);
				jsonobject = new JSONObject(json);
				code = jsonobject.getString("code");
				msg = jsonobject.getString("msg");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}

		@Override
		protected void onPostExecute(Object result) {
			super.onPostExecute(result);
			if (code.equalsIgnoreCase("1")) {
				new MailSender().execute();
			} else {
				Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT)
						.show();
			}
		}

	}

	private class mylocationlistener implements LocationListener {

		private String la;
		private String ln;

		// @Override
		public void onLocationChanged(Location location) {

			if (i == 0) {
				if (location != null) {
					double lat = location.getLatitude();
					double lng = location.getLongitude();
					System.out.println(lat + "(((" + lng);
					la = "" + lat;
					ln = "" + lng;
					desa_f7_ans_lan.setText(la);
					desa_f7_ans_long.setText(ln);
					i++;
				}
			}

		}

		public void onProviderDisabled(String provider) {

			Toast.makeText(Desa_Form7.this, "Error onProviderDisabled",
					Toast.LENGTH_LONG).show();

		}

		public void onProviderEnabled(String provider) {

			Toast.makeText(Desa_Form7.this, "onProviderEnabled",
					Toast.LENGTH_LONG).show();

		}

		public void onStatusChanged(String provider, int status, Bundle extras) {

			Toast.makeText(Desa_Form7.this, "onStatusChanged",
					Toast.LENGTH_LONG).show();

		}

	}

	public boolean isOnline() {
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getActiveNetworkInfo();
		if (netInfo != null && netInfo.isConnected()) {
			return true;
		}
		return false;
	}

	class MailSender extends AsyncTask<Void, Integer, Integer> {

		ProgressDialog pd = null;

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			super.onPreExecute();

		}

		@Override
		protected Integer doInBackground(Void... params) {

			Mail m = new Mail(GMAIL_EMAIL_ID, GMAIL_ACCOUNT_PASSWORD);

			String toAddresses = Global.TO_ADDRESSES;
			m.setToAddresses(toAddresses);
			m.setFromAddress(GMAIL_EMAIL_ID);
			m.setMailSubject("Survey Desk!!!");
			m.setMailBody("Post Has been made by "
					+ Global.username
					+ " **This message has been recieved from Your Survey Desk**"
					+ "<br/>"
					+"&sd_1_1="+desa_f1_1
					+"&sd_1_2="+desa_f1_2
					+"&sd_1_3="+desa_f1_3
					+"&sd_1_4="+desa_f1_4
					+"&sd_1_5="+desa_f1_5
					+"&sd_2_1="+desa_f2_1
					+"&sd_2_2="+desa_f2_2
					+"&sd_2_3="+desa_f2_3
					+"&sd_2_4="+desa_f2_4
					+"&sd_2_5="+desa_f2_5
					+"&sd_2_6a="+desa_f2_6a
					+"&sd_2_6b="+desa_f2_6b
					+"&sd_3_1a="+desa_f3_1a
					+"&sd_3_1b="+desa_f3_1b
					+"&sd_3_211="+desa_f3_211
					+"&sd_3_212="+desa_f3_212
					+"&sd_3_213="+desa_f3_213
					+"&sd_3_214="+desa_f3_214
					+"&sd_3_215="+desa_f3_215
					+"&sd_3_221="+desa_f3_221
					+"&sd_3_222="+desa_f3_222
					+"&sd_3_223="+desa_f3_223
					+"&sd_3_224="+desa_f3_224
					+"&sd_3_225="+desa_f3_225
					+"&sd_3_231="+desa_f3_231
					+"&sd_3_232="+desa_f3_232
					+"&sd_3_233="+desa_f3_233
					+"&sd_3_234="+desa_f3_234
					+"&sd_3_235="+desa_f3_235
					+"&sd_3_3="+desa_f3_3
					+"&sd_3_4="+desa_f3_4
					+"&sd_3_5a="+desa_f3_5a
					+"&sd_3_5b="+desa_f3_5b
					+"&sd_3_5c="+desa_f3_5c
					+"&sd_3_5d="+desa_f3_5d
					+"&sd_3_5e="+desa_f3_5e
					+"&sd_4_1="+desa_f4_1
					+"&sd_4_2a="+desa_f4_2a
					+"&sd_4_2b="+desa_f4_2b
					+"&sd_4_2c="+desa_f4_2c
					+"&sd_4_2d="+desa_f4_2d
					+"&sd_4_2e="+desa_f4_2e
					+"&sd_4_2f="+desa_f4_2f
					+"&sd_4_2g="+desa_f4_2g
					+"&sd_4_2h="+desa_f4_2h
					+"&sd_4_3="+desa_f4_3
					+"&sd_4_4="+desa_f4_4
					+"&sd_4_5="+desa_f4_5
					+"&sd_4_6="+desa_f4_6
					+"&sd_4_7="+desa_f4_7
					+"&sd_4_8="+desa_f4_8
					+"&sd_4_9="+desa_f4_9
					+"&sd_4_10="+desa_f4_10
					+"&sd_4_11a="+desa_f4_11a
					+"&sd_4_11ba="+desa_f4_11ba
					+"&sd_4_11bb="+desa_f4_11bb
					+"&sd_4_11bc="+desa_f4_11bc
					+"&sd_4_11bd="+desa_f4_11bd
					+"&sd_4_11c="+desa_f4_11c
					+"&sd_4_12="+desa_f4_12
					+"&sd_4_13a="+desa_f4_13a
					+"&sd_4_13b="+desa_f4_13b
					+"&sd_4_13c="+desa_f4_13c
					+"&sd_4_14a="+desa_f4_14a
					+"&sd_4_14b="+desa_f4_14b
					+"&sd_4_14c="+desa_f4_14c
					+"&sd_4_14d="+desa_f4_14d
					+"&sd_4_15="+desa_f4_15
					+"&sd_4_16a="+desa_f4_16a
					+"&sd_4_16b="+desa_f4_16b
					+"&sd_4_17="+desa_f4_17
					+"&sd_4_18="+desa_f4_18
					+"&sd_4_19="+desa_f4_19
					+"&sd_4_20="+desa_f4_20
					+"&sd_4_21a="+desa_f4_21a
					+"&sd_4_21b="+desa_f4_21b
					+"&sd_4_22a="+desa_f4_22a
					+"&sd_4_22b="+desa_f4_22b
					+"&sd_4_22c="+desa_f4_22c
					+"&sd_4_22d="+desa_f4_22d
					+"&sd_4_22e="+desa_f4_22e
					+"&sd_5_1="+desa_f5_1
					+"&sd_5_2="+desa_f5_2
					+"&sd_5_3="+desa_f5_3
					+"&sd_5_4="+desa_f5_4
					+"&sd_5_5a="+desa_f5_5a
					+"&sd_5_5b="+desa_f5_5b
					+"&sd_5_5c="+desa_f5_5c
					+"&sd_5_5d="+desa_f5_5d
					+"&sd_5_6="+desa_f5_6
					+"&sd_5_7a="+desa_f5_7a
					+"&sd_5_7b="+desa_f5_7b
					+"&sd_5_8="+desa_f5_8
					+"&sd_5_9a="+desa_f5_9a
					+"&sd_5_9b="+desa_f5_9b
					+"&sd_5_9c="+desa_f5_9c
					+"&sd_5_9d="+desa_f5_9d
					+"&sd_5_10="+desa_f5_10
					+"&sd_5_11="+desa_f5_11
					+"&sd_5_12="+desa_f5_12
					+"&sd_5_13a="+desa_f5_13a
					+"&sd_5_13b="+desa_f5_13b
					+"&sd_6_1="+desa_f6_1
					+"&sd_6_2a="+desa_f6_2a
					+"&sd_6_2b="+desa_f6_2b
					+"&sd_6_3a="+desa_f6_3a
					+"&sd_6_3b="+desa_f6_3b
					+"&sd_6_3c="+desa_f6_3c
					+"&sd_6_3d="+desa_f6_3d
					+"&sd_7_1="+desa_f7_1
					+"&sd_7_2="+desa_f7_2
					+"&sd_7_3="+desa_f7_3
					+"&sd_7_4="+desa_f7_4
					+"&sd_7_5="+desa_f7_5
					+"&sd_7_6="+desa_f7_6
					);

			try {

				if (m.send()) {
					System.out.println("Message sent");
					return 1;
				} else {
					return 2;
				}

			} catch (Exception e) {
				Log.e("MailApp", "Could not send email", e);
			}
			return 3;
		}

		@Override
		protected void onPostExecute(Integer result) {
			super.onPostExecute(result);

			if (result == 1)
			{
				Toast.makeText(Desa_Form7.this, "Email was sent successfully.",
						Toast.LENGTH_LONG).show();
			}
			else if (result == 2)
			{
				Toast.makeText(Desa_Form7.this, "Email was not sent.",
						Toast.LENGTH_LONG).show();
			}
			else if (result == 3)
			{
				Toast.makeText(Desa_Form7.this,	"There was a problem sending the email.",
						Toast.LENGTH_LONG).show();
			}
			Intent intent = new Intent(getApplicationContext(), Home.class);
			startActivity(intent);
			Desa_Form7.this.finish();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		try {

			if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {
				File out = new File(_path);
				// Toast.makeText(getApplicationContext(), "Captured",
				// Toast.LENGTH_SHORT).show();
				Bitmap bmp = BitmapFactory.decodeFile("mnt/sdcard/"
						+ newimgname + ".jpg");
				if (image_flag == 1) {
					img.setImageBitmap(bmp);
				} else if (image_flag == 2) {
					img1.setImageBitmap(bmp);
				}
				filePath = _path;
				if (image_flag == 1) {
					Global.image_path1 = filePath;
				} else if (image_flag == 2) {
					Global.image_path2 = filePath;
				}
				nameimage = newimgname + ".jpg";

			}

			switch (requestCode) {
			case PICK_IMAGE:
				if (resultCode == Activity.RESULT_OK) {
					Uri selectedImageUri = data.getData();

					try {
						// OI FILE Manager
						String filemanagerstring = selectedImageUri.getPath();

						// MEDIA GALLERY
						String selectedImagePath = getPath(selectedImageUri);

						if (selectedImagePath != null) {
							filePath = selectedImagePath;
						} else if (filemanagerstring != null) {
							filePath = filemanagerstring;
						} else {
							// Toast.makeText(getApplicationContext(),
							// "Unknown path",Toast.LENGTH_LONG).show();
							// Log.e("Bitmap", "Unknown path");
							System.out.println("Bitmap" + "Unknown path");
						}

						if (filePath != null) {
							String[] temp;

							/* delimiter */
							String delimiter = "/";
							/*
							 * given string will be split by the argument
							 * delimiter provided.
							 */
							temp = filePath.split(delimiter);
							/* print substrings */
							for (int i = 0; i < temp.length; i++) {
								System.out.println(temp[i]);
								nameimage = temp[i];
								System.out.println(nameimage);
							}
							decodeFile(filePath);
							if (image_flag == 1) {
								Global.image_path1 = filePath;
							} else if (image_flag == 2) {
								Global.image_path2 = filePath;
							}
						} else {
							bitmap = null;
						}
					} catch (Exception e) {

						System.out.println(e);
					}
				}
				break;
			default:
			}
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e);
		}
	}

	public String getPath(Uri uri) {
		try {
			String[] projection = { MediaStore.Images.Media.DATA };
			Cursor cursor = managedQuery(uri, projection, null, null, null);
			if (cursor != null) {
				// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
				// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE
				// MEDIA
				int column_index = cursor
						.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
				cursor.moveToFirst();
				return cursor.getString(column_index);
			} else
				return null;
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e);
		}
		return null;
	}

	public void decodeFile(String filePath) {
		try {
			// Decode image size
			BitmapFactory.Options o = new BitmapFactory.Options();
			o.inJustDecodeBounds = true;
			BitmapFactory.decodeFile(filePath, o);

			// The new size we want to scale to
			final int REQUIRED_SIZE = 1024;

			// Find the correct scale value. It should be the power of 2.
			int width_tmp = o.outWidth, height_tmp = o.outHeight;
			int scale = 1;
			while (true) {
				if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
					break;
				width_tmp /= 2;
				height_tmp /= 2;
				scale *= 2;
			}

			// Decode with inSampleSize
			BitmapFactory.Options o2 = new BitmapFactory.Options();
			o2.inSampleSize = scale;
			bitmap = BitmapFactory.decodeFile(filePath, o2);

			if (image_flag == 1) {
				img.setImageBitmap(bitmap);
			} else if (image_flag == 2) {
				img1.setImageBitmap(bitmap);
			}
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e);
		}
	}

	@Override
	public Dialog onCreateDialog(int id) {

		switch (id) {
		case CUSTOM_DIALOG_ID: {
			try {
				dialog = new Dialog(Desa_Form7.this);

				dialog.setContentView(R.layout.choosecamlayout);
				dialog.setTitle(" Select");

				fromgallery = (TextView) dialog.findViewById(R.id.fromgallery);
				fromgallery.setOnClickListener(new OnClickListener() {

					public void onClick(View v) {
						// TODO Auto-generated method stub
						dialog.dismiss();
						choosefromgallery();
					}
				});

				takeimage = (TextView) dialog.findViewById(R.id.captphoto);
				takeimage.setOnClickListener(new OnClickListener() {

					public void onClick(View v) {
						// TODO Auto-generated method stub
						dialog.dismiss();
						takephoto();

					}
				});

				break;
			} catch (Exception e) {
				// TODO: handle exception
				System.out.println(e);
			}
		}

		}
		return dialog;
	}

	public String generatePin() throws Exception {
		Random generator = new Random();
		generator.setSeed(System.currentTimeMillis());

		int num = generator.nextInt(99999) + 99999;
		if (num < 100000 || num > 999999) {
			num = generator.nextInt(99999) + 99999;
			if (num < 100000 || num > 999999) {
				throw new Exception("Unable to generate random at this time..");
			}
		}
		return "" + num;
	}

	private void takephoto() {
		// Toast.makeText(getApplicationContext(), "Capture",
		// Toast.LENGTH_SHORT).show();
		try {
			newimgname = generatePin().trim().toString();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		_path = Environment.getExternalStorageDirectory() + "/" + newimgname
				+ ".jpg";
		File file = new File(_path);
		Uri outputFileUri = Uri.fromFile(file);

		Intent intent = new Intent(
				android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
		startActivityForResult(intent, 0);
	}

	private void choosefromgallery() {
		try {
			Intent intent = new Intent();
			intent.setType("image/*");
			intent.setAction(Intent.ACTION_GET_CONTENT);
			startActivityForResult(
					Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
		} catch (Exception e) {
			Toast.makeText(getApplicationContext(), e.getMessage(),
					Toast.LENGTH_LONG).show();
			System.out.println(e);
		}
	}

	public int doing()

	{

		try {
			fileName = Global.image_path1;
			HttpURLConnection conn = null;
			DataOutputStream dos = null;
			String lineEnd = "\r\n";
			String twoHyphens = "--";
			String boundary = "*****";
			int bytesRead, bytesAvailable, bufferSize;
			byte[] buffer;
			int maxBufferSize = 1 * 1024 * 1024;
			File sourceFile = new File(Global.image_path1);
			if (!sourceFile.isFile()) {

			}
			try {
				FileInputStream fileInputStream = new FileInputStream(
						sourceFile);
				URL url = new URL(Global.upload_url);
				conn = (HttpURLConnection) url.openConnection();
				conn.setDoInput(true);
				conn.setDoOutput(true);
				conn.setUseCaches(false);
				conn.setRequestMethod("POST");
				conn.setRequestProperty("Connection", "Keep-Alive");
				conn.setRequestProperty("ENCTYPE", "multipart/form-data");
				conn.setRequestProperty("Content-Type",
						"multipart/form-data;boundary=" + boundary);
				conn.setRequestProperty("uploadedfile", fileName);
				dos = new DataOutputStream(conn.getOutputStream());

				dos.writeBytes(twoHyphens + boundary + lineEnd);
				dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
						+ fileName + "\"" + lineEnd);
				dos.writeBytes(lineEnd);

				bytesAvailable = fileInputStream.available();

				bufferSize = Math.min(bytesAvailable, maxBufferSize);
				buffer = new byte[bufferSize];

				bytesRead = fileInputStream.read(buffer, 0, bufferSize);

				while (bytesRead > 0) {
					dos.write(buffer, 0, bufferSize);
					bytesAvailable = fileInputStream.available();
					bufferSize = Math.min(bytesAvailable, maxBufferSize);
					bytesRead = fileInputStream.read(buffer, 0, bufferSize);
				}

				dos.writeBytes(lineEnd);
				dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
				serverResponseCode = conn.getResponseCode();
				serverResponseMessage = conn.getResponseMessage();
				if (serverResponseCode == 200) {
					runOnUiThread(new Runnable() {
						public void run() {

						}
					});
				}

				fileInputStream.close();
				dos.flush();
				dos.close();

			} catch (MalformedURLException ex) {

				System.out.println(ex.getMessage());
				// Toast.makeText(Desa_Form7.this, "MalformedURLException",
				// Toast.LENGTH_SHORT).show();
			} catch (Exception e) {

				System.out.println(e.getMessage());
				// Toast.makeText(Desa_Form7.this, "Exception : " +
				// e.getMessage(), Toast.LENGTH_SHORT).show();
			}

		} catch (Exception e) {
			System.out.println(e);
		}
		return 1;

	}

	public int doing1()

	{

		try {
			fileName = Global.image_path2;
			HttpURLConnection conn = null;
			DataOutputStream dos = null;
			String lineEnd = "\r\n";
			String twoHyphens = "--";
			String boundary = "*****";
			int bytesRead, bytesAvailable, bufferSize;
			byte[] buffer;
			int maxBufferSize = 1 * 1024 * 1024;
			File sourceFile = new File(Global.image_path2);
			if (!sourceFile.isFile()) {

			}
			try {
				FileInputStream fileInputStream = new FileInputStream(
						sourceFile);
				URL url = new URL(Global.upload_url);
				conn = (HttpURLConnection) url.openConnection();
				conn.setDoInput(true);
				conn.setDoOutput(true);
				conn.setUseCaches(false);
				conn.setRequestMethod("POST");
				conn.setRequestProperty("Connection", "Keep-Alive");
				conn.setRequestProperty("ENCTYPE", "multipart/form-data");
				conn.setRequestProperty("Content-Type",
						"multipart/form-data;boundary=" + boundary);
				conn.setRequestProperty("uploadedfile", fileName);
				dos = new DataOutputStream(conn.getOutputStream());

				dos.writeBytes(twoHyphens + boundary + lineEnd);
				dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
						+ fileName + "\"" + lineEnd);
				dos.writeBytes(lineEnd);

				bytesAvailable = fileInputStream.available();

				bufferSize = Math.min(bytesAvailable, maxBufferSize);
				buffer = new byte[bufferSize];

				bytesRead = fileInputStream.read(buffer, 0, bufferSize);

				while (bytesRead > 0) {
					dos.write(buffer, 0, bufferSize);
					bytesAvailable = fileInputStream.available();
					bufferSize = Math.min(bytesAvailable, maxBufferSize);
					bytesRead = fileInputStream.read(buffer, 0, bufferSize);
				}

				dos.writeBytes(lineEnd);
				dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
				serverResponseCode1 = conn.getResponseCode();
				serverResponseMessage1 = conn.getResponseMessage();
				if (serverResponseCode1 == 200) {
					runOnUiThread(new Runnable() {
						public void run() {

						}
					});
				}

				fileInputStream.close();
				dos.flush();
				dos.close();

			} catch (MalformedURLException ex) {

				System.out.println(ex.getMessage());
				// Toast.makeText(Desa_Form7.this, "MalformedURLException",
				// Toast.LENGTH_SHORT).show();
			} catch (Exception e) {
				System.out.println(e.getMessage());
				// Toast.makeText(Desa_Form7.this, "Exception : " +
				// e.getMessage(), Toast.LENGTH_SHORT).show();
			}

		} catch (Exception e) {
			System.out.println(e);
		}
		return 1;

	}

}
